//    Copyright (C) 2013  <lugocreation@gmail.com>
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>
package org.jpgolay.wi.availability;

import java.awt.*;
import javax.swing.*;
import org.jpgolay.gui.fixed.*;
import org.jpgolay.wi.util.WIUtil;

public class AvailabilityGUI extends JInternalFrame {

    public AvailabilityGUI() {
        jContentPane = null;
        mainPanel = null;
        realEstateIdLabelAndTextField = null;
        customerIdLabelAndTextField = null;
        beginDateLabelAndDateComboBox = null;
        endDateLabelAndDateComboBox = null;
        confirmedLabelAndComboBox = null;
        optionLabelAndComboBox = null;
        notesScrollPane = null;
        notesTextArea = null;
        saveButton = null;
        cancelButton = null;
        initialize();
    }

    private void initialize() {
        setTitle("R\351servation");
        setFrameIcon(new ImageIcon(getClass().getResource("/org/jpgolay/gui/images/sch.png")));
        setSize(330, 326);
        setContentPane(getJContentPane());
    }

    private JPanel getJContentPane() {
        if (jContentPane == null) {
            jContentPane = new JPanel();
            jContentPane.setLayout(new BorderLayout());
            jContentPane.add(getMainPanel(), "Center");
        }
        return jContentPane;
    }

    private JPanel getMainPanel() {
        if (mainPanel == null) {
            FlowLayout flowLayout1 = new FlowLayout();
            mainPanel = new JPanel();
            mainPanel.setLayout(flowLayout1);
            flowLayout1.setHgap(5);
            flowLayout1.setVgap(2);
            mainPanel.add(getRealEstateIdLabelAndTextField(), null);
            mainPanel.add(getCustomerIdLabelAndTextField(), null);
            mainPanel.add(getBeginDateLabelAndDateComboBox(), null);
            mainPanel.add(getEndDateLabelAndDateComboBox(), null);
            mainPanel.add(getConfirmedLabelAndComboBox(), null);
            mainPanel.add(getOptionLabelAndComboBox(), null);
            mainPanel.add(getNotesScrollPane(), null);
            mainPanel.add(getSaveButton(), null);
            mainPanel.add(getCancelButton(), null);
        }
        return mainPanel;
    }

    private LabelAndTextField getRealEstateIdLabelAndTextField() {
        if (realEstateIdLabelAndTextField == null) {
            realEstateIdLabelAndTextField = new LabelAndTextField();
            realEstateIdLabelAndTextField.setLabel("Num\351ro du bien");
            realEstateIdLabelAndTextField.getTextField().setEditable(false);
        }
        return realEstateIdLabelAndTextField;
    }

    private LabelAndTextField getCustomerIdLabelAndTextField() {
        if (customerIdLabelAndTextField == null) {
            customerIdLabelAndTextField = new LabelAndTextField();
            customerIdLabelAndTextField.setLabel("Num\351ro du client");
            customerIdLabelAndTextField.getTextField().setEditable(false);
        }
        return customerIdLabelAndTextField;
    }

    private LabelAndDateComboBox getBeginDateLabelAndDateComboBox() {
        if (beginDateLabelAndDateComboBox == null) {
            beginDateLabelAndDateComboBox = new LabelAndDateComboBox();
            beginDateLabelAndDateComboBox.setLabel("Date d\351but");
        }
        return beginDateLabelAndDateComboBox;
    }

    private LabelAndDateComboBox getEndDateLabelAndDateComboBox() {
        if (endDateLabelAndDateComboBox == null) {
            endDateLabelAndDateComboBox = new LabelAndDateComboBox();
            endDateLabelAndDateComboBox.setLabel("Date fin");
        }
        return endDateLabelAndDateComboBox;
    }

    private LabelAndComboBox getConfirmedLabelAndComboBox() {
        if (confirmedLabelAndComboBox == null) {
            confirmedLabelAndComboBox = new LabelAndComboBox();
            confirmedLabelAndComboBox.setLabel("Etat");
            confirmedLabelAndComboBox.setList(WIUtil.AVAILABILITY_CONFIRMED);
            confirmedLabelAndComboBox.setSelectedIndex(0);
        }
        return confirmedLabelAndComboBox;
    }

    private LabelAndComboBox getOptionLabelAndComboBox() {
        if (optionLabelAndComboBox == null) {
            optionLabelAndComboBox = new LabelAndComboBox();
            optionLabelAndComboBox.setLabel("Option");
            optionLabelAndComboBox.setList(WIUtil.AVAILABILITY_OPTION);
            optionLabelAndComboBox.setSelectedIndex(0);
        }
        return optionLabelAndComboBox;
    }

    private JScrollPane getNotesScrollPane() {
        if (notesScrollPane == null) {
            notesScrollPane = new JScrollPane();
            notesScrollPane.setPreferredSize(new Dimension(306, 80));
            notesScrollPane.setViewportView(getNotesTextArea());
            notesScrollPane.setHorizontalScrollBarPolicy(31);
        }
        return notesScrollPane;
    }

    private JTextArea getNotesTextArea() {
        if (notesTextArea == null) {
            notesTextArea = new JTextArea();
            notesTextArea.setPreferredSize(new Dimension(280, 80));
            notesTextArea.setLineWrap(true);
            notesTextArea.setWrapStyleWord(true);
        }
        return notesTextArea;
    }

    private JButton getSaveButton() {
        if (saveButton == null) {
            saveButton = new JButton();
            saveButton.setIcon(new ImageIcon(getClass().getResource("/org/jpgolay/wi/images/vu.png")));
            saveButton.setToolTipText("Enregistrer");
            saveButton.setPreferredSize(new Dimension(25, 25));
        }
        return saveButton;
    }

    private JButton getCancelButton() {
        if (cancelButton == null) {
            cancelButton = new JButton();
            cancelButton.setPreferredSize(new Dimension(25, 25));
            cancelButton.setToolTipText("Annuler");
            cancelButton.setIcon(new ImageIcon(getClass().getResource("/org/jpgolay/wi/images/croix.png")));
        }
        return cancelButton;
    }

    public String getRealEstateId() {
        return getRealEstateIdLabelAndTextField().getVal();
    }

    public void setRealEstateId(String txt) {
        getRealEstateIdLabelAndTextField().setVal(txt);
    }

    public String getCustomerId() {
        return getCustomerIdLabelAndTextField().getVal();
    }

    public void setCustomerId(String txt) {
        getCustomerIdLabelAndTextField().setVal(txt);
    }

    public String getBeginDate() {
        return getBeginDateLabelAndDateComboBox().getDate();
    }

    public void setBeginDate(String txt) {
        getBeginDateLabelAndDateComboBox().setDate(txt);
    }

    public String getEndDate() {
        return getEndDateLabelAndDateComboBox().getDate();
    }

    public void setEndDate(String txt) {
        getEndDateLabelAndDateComboBox().setDate(txt);
    }

    public String getConfirmed() {
        return getConfirmedLabelAndComboBox().getSelectedString();
    }

    public void setConfirmed(String txt) {
        getConfirmedLabelAndComboBox().setSelectedString(txt);
    }

    public String getOption() {
        return getOptionLabelAndComboBox().getSelectedString();
    }

    public void setOption(String txt) {
        getOptionLabelAndComboBox().setSelectedString(txt);
    }

    public String getNotes() {
        return getNotesTextArea().getText();
    }

    public void setNotes(String txt) {
        getNotesTextArea().setText(txt);
    }

    public JButton getSave() {
        return getSaveButton();
    }

    public JButton getCancel() {
        return getCancelButton();
    }

    public void initFields() {
        setRealEstateId("");
        setCustomerId("");
        setBeginDate("");
        setEndDate("");
        setConfirmed("");
        setOption("");
        setNotes("");
    }
    private JPanel jContentPane;
    private JPanel mainPanel;
    private LabelAndTextField realEstateIdLabelAndTextField;
    private LabelAndTextField customerIdLabelAndTextField;
    private LabelAndDateComboBox beginDateLabelAndDateComboBox;
    private LabelAndDateComboBox endDateLabelAndDateComboBox;
    private LabelAndComboBox confirmedLabelAndComboBox;
    private LabelAndComboBox optionLabelAndComboBox;
    private JScrollPane notesScrollPane;
    private JTextArea notesTextArea;
    private JButton saveButton;
    private JButton cancelButton;
}
